package com.pubinfo.passbook.api.controller.bill;

import com.alibaba.fastjson.JSONObject;
import com.pubinfo.passbook.api.eip.UserInfoService;
import com.pubinfo.passbook.common.entity.TSystemRole;
import com.pubinfo.passbook.common.model.dto.tax.InvoicePageParamObj;
import com.pubinfo.passbook.common.model.vo.InvoiceList;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.model.vo.base.MyPage;
import com.pubinfo.passbook.common.service.master.TInvoiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "invoice")
@Api(tags = "发票管理")
@Slf4j
public class TInvoiceController {
  @Autowired
  TInvoiceService invoiceService;
  
  @Resource
  UserInfoService userInfoService;
  
  @PostMapping("list")
  @ApiOperation(value = "查询发票列表数据")
  public JsonResult<MyPage<InvoiceList>> listInterfaceClassify(@RequestBody InvoicePageParamObj paramObj) {
    TSystemRole role = userInfoService.getRoleInfo();
    return JsonResult.success(invoiceService.listTInvoice(paramObj, role));
  }
  
  @GetMapping("details/{id}")
  @ApiOperation(value = "查询详情")
  public JsonResult<JSONObject> details(@PathVariable("id") String id) {
    return JsonResult.success(invoiceService.detailsInvoiceById(id));
  }
  
  @DeleteMapping("remove/{id}")
  @ApiOperation(value = "删除一条发票")
  public JsonResult<Boolean> delete(@PathVariable("id") String id) {
    return JsonResult.success(invoiceService.deleteInvoiceById(id));
  }
  
  @PostMapping("removeBatch")
  @ApiOperation(value = "批量删除发票")
  public JsonResult<Integer> delete(@RequestBody String[] ids) {
    
    return JsonResult.success(invoiceService.batchDeleteInvoiceByIds(CollectionUtils.arrayToList(ids)));
  }
}
